﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;

namespace Monocle.Models.Facebook
{
    public static class FacebookGallery
    {
        private class PictureCollection
        {
            public List<Picture> data { get; set; }
            public String id { get; set; }
        }
        private class Picture
        {
            public String picture { get; set; }
            public String id { get; set; }
            public String link { get; set; }
            public String created_time { get; set; }
            public String source { get; set; }

            public List<Image> images { get; set; }
        }

        private class Image
        {
            public String width { get; set; }
            public String height { get; set; }
            public String source { get; set; }
        }

        public static String GetGalleryGraph(String stream, String id)
        {
            var Gallerys = JsonConvert.DeserializeObject<PictureCollection>(stream);
            Gallerys.id = id;
            Gallerys.data.Sort((x, y) => DateTime.Parse(x.created_time).CompareTo(DateTime.Parse(y.created_time)));
            return JsonConvert.SerializeObject(Gallerys);
        }

        private class GalleryCollection
        {
            public List<Gallery> data { get; set; }

        }

        private class Gallery
        {
            public String name { get; set; }
            public String id { get; set; }
        }

        public static Dictionary<String, String> GetGalleryList(String stream)
        {
            var Gallerys = JsonConvert.DeserializeObject<GalleryCollection>(stream);
            var list = new Dictionary<String, String>();
            foreach (var item in Gallerys.data)
            {
                list.Add(item.id, item.name);
            }
            return list;
        }
    }
}